package com.ecoolex.ying.space.core.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ecoolex.admin.system.core.manager.AdminServiceAccountConfigManager;
import com.ecoolex.admin.system.core.service.account.AccountService;
import com.ecoolex.admin.system.entity.AdminServiceAccountConfig;
import com.ecoolex.admin.system.enums.AdminServiceAccountConfigServiceType;
import com.ecoolex.framework.common.enums.ResultCode;
import com.ecoolex.framework.common.exception.BizException;
import com.google.common.collect.Maps;

/**
 * 发送阿里云短信服务
 * @author Stephen_cao
 *
 */
@Component
public class SmsService {

	@Autowired
    private AccountService accountService;
	
	@Autowired
	private AdminServiceAccountConfigManager adminServiceAccountConfigManager;
	
	public void sendEstateProjectActivityGoodsOrderSms(String customerName,String orderNo,String countryCode, String phone) {
		AdminServiceAccountConfig adminServiceAccountConfig = adminServiceAccountConfigManager.getByServiceType(AdminServiceAccountConfigServiceType.SMS.real());
		Map<String, Object> params = Maps.newHashMap();
		params.put("orderNo", orderNo);
		params.put("customerName", customerName);
		params.put("appName", "yingkongjian");
		BizException.wrap(() -> {
			accountService.sendSms(adminServiceAccountConfig.getServiceAccountConfigId(), 
				"{\"signName\":\"映空间\",\"templateCode\":\"SMS_201680805\"}", 
				countryCode, 
				phone, 
				params);
		},ResultCode.SYSTEM.build(1),"发送短信异常");
	}
}
